<template>
<view>
        <u-navbar title="个人信息" :background="background" back-icon-color="#efefef" title-color="#efefef"></u-navbar>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
			<u-form-item  label-width="120" :label-position="labelPosition" label="用户名" prop="name">
				<u-input :border="border" placeholder="请输入用户名" v-model="model.userName" type="text"></u-input>
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="性别" prop="sex">
				<u-input :border="border" type="text" v-model="model.sexName" placeholder="请选择性别"></u-input>
			</u-form-item>
<!-- 			<u-form-item :label-position="labelPosition" label="密码" prop="password">
				<u-input :password-icon="true" :border="border" type="password" v-model="model.password" placeholder="请输入密码"></u-input>
			</u-form-item> -->
			<!-- <u-form-item :label-position="labelPosition" label="确认密码" label-width="150" prop="rePassword">
				<u-input :border="border" type="password" v-model="model.rePassword" placeholder="请确认密码"></u-input>
			</u-form-item> -->
            <u-form-item  :label-position="labelPosition" label="邮箱" prop="email">
            	<u-input :border="border" placeholder="请输入正确邮箱" v-model="model.email" type="text"></u-input>
            </u-form-item>
			<u-form-item :label-position="labelPosition" label="手机号码" prop="phone" label-width="150">
				<u-input :border="border" placeholder="请输入手机号" v-model="model.phoneNumber" type="number"></u-input>
			</u-form-item>
			<!-- 此处switch的slot为right，如果不填写slot名，也即<u-switch v-model="model.remember"></u-switch>，将会左对齐 -->
<!-- 			<u-form-item :label-position="labelPosition" label="上传图片" prop="photo" label-width="150">
				<u-upload width="160" height="160"></u-upload>
			</u-form-item> -->
		</u-form>
		<!-- <view class="agreement">
			<u-checkbox v-model="check" @change="checkboxChange"></u-checkbox>
			<view class="agreement-text">
				勾选代表同意用户协议
			</view>
		</view>
		<u-button @click="submit">提交</u-button>
		<u-action-sheet :list="actionSheetList" v-model="actionSheetShow" @click="actionSheetCallback"></u-action-sheet> -->
	</view>
    </view>
</template>

<script>
    import { getMyInfo } from "@/api/login.js"
export default {
	data() {
		let that = this;
		return {
            background: {
                backgroundImage: 'linear-gradient(45deg, rgb(255, 40, 0), rgb(147, 0, 0))'
                // backgroundColor: "#ffffff"
            },
			model: {
				// userName: '',
				// sex: '',
				// agreement: false,
				// phoneNumber: '',
    //             email:'',
				// password: '',
				// rePassword: '',
				// remember: false,
				// photo: ''
			},
			
			
			border: false,
			check: false,
			selectStatus: 'close',
			actionSheetList: [
				{
					text: '男'
				},
				{
					text: '女'
				},

			],
            actionSheetShow: false,
            labelPosition: 'left',
            codeTips: '',
            myId: 0,
            // errorType: ['message'],
		};
	},
	onLoad(options) {
        this.myId=options.userId

	},
    onShow() {
        if(this.myId!=0)
        this.getMyInfo()
    },
	computed: {
		borderCurrent() {
			return this.border ? 0 : 1;
		}
	},
	onReady() {
		// this.$refs.uForm.setRules(this.rules);
	},
	methods: {
        getMyInfo(){
            const _this=this
            getMyInfo({
                userId: this.myId
            }).then(function(res){
                _this.model=res.data.data
                if(_this.model.sex==1){
                    _this.model.sexName="男"
                    }
                    else{
                       _this.model.sexName="女" 
                    }
            })
        },
		// submit() {
  //           const _this =this
  //           let sex = 1
  //           if(this.model.sex=='男'){
  //               sex=1
  //           }
  //            else{
  //                sex=2
  //            }
              
  //           const user = {
  //               userName: this.model.name,
  //               email: this.model.email,
  //               sex: sex,
  //               phoneNumber: this.model.phone,
  //               password: this.model.rePassword,
  //           }
		// 	this.$refs.uForm.validate(valid => {
		// 		if (valid) {
		// 			if(!this.model.agreement) return this.$u.toast('请勾选协议');
  //                   register(user).then(function(res){
  //                       console.log(res.data)
  //                       if(res.data.code==200){
  //                       uni.showLoading({
  //                               title: '注册成功！'
  //                           })
  //                           setTimeout(function() {
  //                               uni.hideLoading();
  //                               uni.navigateTo({
  //                                   url: '/pages/login/index'
  //                               })
  //                           }, 1500);
                                
  //                           }else{
  //                               uni.showLoading({
  //                                       title: '注册失败！请重试'
  //                                   })
  //                                   setTimeout(function() {
  //                                       uni.hideLoading();
  //                                   }, 1500);
  //                           }
                        
  //                   })
  //                   // console.log(this.model)
		// 			// console.log('验证通过');
		// 		} else {
		// 			console.log('验证失败');
		// 		}
		// 	});
		// },
		// 点击actionSheet回调
		actionSheetCallback(index) {
			uni.hideKeyboard();
			this.model.sex = this.actionSheetList[index].text;
		},
		
		// 勾选版权协议
		checkboxChange(e) {
			this.model.agreement = e.value;
		},
		
	}
};
</script>

<style scoped lang="scss">
.wrap {
	padding: 30rpx;
}

.agreement {
	display: flex;
	align-items: center;
	margin: 40rpx 0;

	.agreement-text {
		padding-left: 8rpx;
		color: $u-tips-color;
	}
}
</style>
